Skip to content

PostgreSQL infrastructure: per-module DBs, initdb, CNPG backup#11

Open
dnplkndll wants to merge 13 commits intomainfrom
feat/drizzle-orm-infra
Open

PostgreSQL infrastructure: per-module DBs, initdb, CNPG backup#11
dnplkndll wants to merge 13 commits intomainfrom
feat/drizzle-orm-infra

Conversation

@dnplkndll
Copy link
Owner

@dnplkndll dnplkndll commented Mar 15, 2026

Summary

Infrastructure for dual MySQL/PostgreSQL support in B1Stack.

Changes

  • docker/api/initdb.sh: Rewritten to support both MySQL and PostgreSQL
    • PG: creates per-module databases (membership, attendance, etc.) matching MySQL layout
    • PG: applies DDL from tools/dbScripts/pg/ + stored functions
    • MySQL: applies DDL from tools/dbScripts/ + stored procedures
  • postgres/init/02-create-module-dbs.sql: Docker entrypoint script that creates per-module PG databases on first start
  • helm/b1stack/templates/cnpg-cluster.yaml: CNPG backup configuration with Barman ObjectStore (S3, gzip, daily schedule)
  • helm/b1stack/values.b1-postgres.yaml: S3 backup config for b1-postgres namespace (30-day retention)

Architecture decision

Chose per-module databases over single-DB-with-schemas for PostgreSQL:

  • Matches MySQL layout (1 database per module)
  • No code changes needed in getDb() or connection string parsing
  • Simpler connection string management
  • Test infrastructure works identically on both dialects

Related

Test plan

  • Docker compose PG profile starts and initializes cleanly
  • initdb.sh creates per-module databases and applies all DDL
  • 299 integration tests pass on both MySQL and PostgreSQL
  • Helm deploy to b1-postgres namespace with CNPG
  • Playwright E2E against PG deployment

🤖 Generated with Claude Code

dnplkndll and others added 11 commits March 15, 2026 06:52
Support the API's migration from raw SQL dbScripts to drizzle-kit
managed migrations with dual MySQL/PostgreSQL dialect support.

- docker-compose: bind-mount tools/ and drizzle/ into API container
- Dockerfile.prod: COPY drizzle/ directory into prod image
- initdb.sh: rewrite to apply drizzle migration SQL files from
  drizzle/<dialect>/<module>/ instead of per-table SQL from dbScripts/;
  MySQL stored procs loaded separately by name whitelist
- load-tests: fix unqualified table name, add PG seed variant
- repos.yaml: update B1Admin branch reference

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Prefix services INSERT with attendance. schema (was inserting into
  wrong schema since PG uses schemas not separate databases)
- Add 2,000 groupMembers via generate_series (matching MySQL version)
- Add members count to verification query

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Next.js dev mode compiles on first request. In CI runners this
exceeds 180s consistently — failing on both main and PR branches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
B1App returns 500 on all routes due to missing
@/styles/vendor/pages.css in ChurchApps/B1App upstream.
This blocks the wait-ready health check indefinitely.

- Add WAIT_SERVICES env var to wait-ready.sh for selective checks
- Skip B1App wait, E2E tests, and artifact upload in CI
- Revert timeout to 180s (sufficient without B1App)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The B1App CSS import issue (missing src/styles/vendor/pages.css) is now
fixed on dnplkndll/B1App#fix/missing-vendor-css (upstream PR: ChurchApps/B1App#460).

- Add fix/missing-vendor-css to B1App merges in repos.yaml
- Restore B1App in wait-ready (was excluded with WAIT_SERVICES filter)
- Remove skip comments for B1App E2E tests
- Increase WAIT_TIMEOUT to 300s (B1App Next.js cold-compile needs time)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Upstream @churchapps/apphelper-donations@0.6.18 declares a peer dep on
@churchapps/helpers@"file:../helpers" which cannot resolve in CI. This
matches the same workaround used in the Docker build (commit 3991dc1).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
B1App has an upstream CSS resolution issue that causes 500 errors on
startup, blocking the wait-ready script. Since B1Admin E2E tests only
need the API and B1Admin services, use WAIT_SERVICES to skip B1App.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests with retries take ~80min on CI. Increase timeout from 90 to 120
minutes. Add summary step to show pass/fail counts and failed test
names in CI logs for easier debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch PG from single-DB-with-schemas to per-module databases,
matching the MySQL layout for simpler dual-dialect support.

- postgres/init/02-create-module-dbs.sql: create 7 per-module databases
  on first container start
- initdb.sh PG section: apply DDL from tools/dbScripts/pg/ to each
  module's own database (was applying drizzle migrations to schemas)
- initdb.sh MySQL section: apply DDL from tools/dbScripts/ (was drizzle)
- Both sections: load stored functions after table creation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add optional Barman ObjectStore backup to CNPG cluster template:
- S3-compatible endpoint with gzip compression (WAL + data)
- ScheduledBackup CRD for daily automated backups (2 AM)
- 30-day retention policy
- Configured for b1-postgres namespace in values.b1-postgres.yaml

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dnplkndll dnplkndll changed the title Drizzle-kit migration infrastructure for API PostgreSQL infrastructure: per-module DBs, initdb, CNPG backup Mar 25, 2026
dnplkndll and others added 2 commits March 24, 2026 22:08
- _helpers.tpl: connStr uses module name as PG database (not b1stack)
- cnpg-cluster.yaml: grant CREATEDB to app user (replaces schema
  creation — initdb.sh creates per-module databases instead)
- Dockerfile.prod: remove stale COPY drizzle/ line

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Api: feat/drizzle-orm → feat/kysely-orm (branch renamed)
- B1Admin: remove feat/playwright-e2e-clean (merged upstream as #367)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant